package com.zjx.mhxykey.util;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileUtil {
    public static boolean saveToExternalCache(Context context, Bitmap bitmap, String filename) {
        File cacheDir = context.getExternalCacheDir();
        if (cacheDir == null) {
            Log.e("ImageSaver", "外部缓存目录不可用");
            return false;
        }

        File imageFile = new File(cacheDir, filename);

        try (FileOutputStream out = new FileOutputStream(imageFile)) {
            bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
            return true;
        } catch (IOException e) {
            Log.e("ImageSaver", "保存图片失败", e);
            return false;
        }
    }



}
